<%@ page language="java" import="java.util.*,mySql.*" pageEncoding="utf-8"%>
<%@ page import="show_shop.*" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>shop_car</title>
    


	<link rel="stylesheet" type="text/css" href="css/shop_car.css">

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> 
<script> 
$(function(){ 
$(".add").click(function(){ 
var t=$(this).parent().find('input[class*=text_box]'); 
t.val(parseInt(t.val())+1) 
setTotal(); 
}) 
$(".min").click(function(){ 
var t=$(this).parent().find('input[class*=text_box]'); 
t.val(parseInt(t.val())-1) 
if(parseInt(t.val())<0){ 
t.val(0); 
} 
setTotal(); 
}) 
function setTotal(){ 
var s=0; 
$("#all_mid_mid ").each(function(){ 
s+=parseInt($(this).find('input[class*=text_box]').val())*parseFloat($(this).find('span[class*=price]').text()); 
}); 
$("#p2_2").html(s.toFixed(2)); 
} 
setTotal(); 

}) 
</script> 
  </head>
  
 <body>
   <!-- header begin -->
   <div class="header">
	<div class="top-header">
	<div class="phone">
	<ul>
	<li class="tele"></li>
	<li class="telenum">
	<p>13739477470</p>
	</li>
	</ul>
	</div>
	
	<div class="logo">
	<h1><a href="http://localhost:8080/practise/index.jsp">Welcome</a></h1>
	</div>
	
	<div class="login_shopcar">
		<%
		user_bean user=new user_bean();
		user=(user_bean)session.getAttribute("feng");
		if(user!=null)
		{
			out.print("欢迎您:"+user.getUsername());		
		%>
		<br><a href="http://localhost:8080/practise/jsp/cancel.jsp" class="cancel">注销</a>
		<% 
		}
		else
		{
	%> 
	<div class="left">
		<div class="left_1"><a href="http://localhost:8080/practise/jsp/login.jsp">Login</a></div>
	</div>
	<% }
	%>
	<div class="right">
	<%
		if(user!=null)
		{
	 %>
	<span class="shopcar_money">
	 $0.00 
	</span>
	<a href="http://localhost:8080/practise/jsp/shop_car.jsp?id=500">
	<img src="image/bag.png"/></a>
	<%
		}		
		else
		{
	 %>
			<a onclick="test()">
		<img src="image/bag.png"/></a>
	<%
		}
	 %>
	</div>
	</div>
</div>
   </div>
   <!-- header end -->
   
   <!-- banner begin -->
   <div class="top_banner">
   <div class="navigation">
   <ul>
   <li><a href="http://localhost:8080/practise/jsp/head.jsp">首页</a></li>
   <li><a href="#">外国菜</a></li>
   <li><a href="#">中国菜</a></li>
   <li><a href="#">外国零食</a></li>
   <li><a href="#">中国零食</a></li>
   <li><a href="#">关于我们</a></li>
   </ul>
   </div>
 
 <div class="bottom_banner">
 <div class="content_input">
 <p>关键字:</p>
 <span><a href="#"><input type="text"></a></span>
 <a href="#"><img src="image/research.png" /></a>
 </div>

 </div>
   </div>
   <!-- banner end -->
   
   <!-- body_content begin -->
   
   <!-- all begin -->
   <div class="all">
   
   <div class="all_top">
   <h1>购物车</h1>
   </div>

     <%
  		ArrayList<goods_bean> goods=new ArrayList<goods_bean>();
   		path="http://localhost:8080/practise/servlet/shop";
   		response.setHeader("refresh", "2000;URL="+path);
   
   		goods=(ArrayList<goods_bean>)session.getAttribute("feng_goods");
   	
   	
   		ArrayList<goods_bean>  shop_car=new ArrayList<goods_bean>();
   		goods_bean shop_car_bean=new goods_bean();
   		
   		
   		String a=request.getParameter("id");
   		Integer id_1=Integer.parseInt(a);
   		int i=0,j=0;
   		int flag=0;
   		if((ArrayList<goods_bean>)session.getAttribute("car_session")!=null)
   		{
   			shop_car=(ArrayList<goods_bean>)session.getAttribute("car_session");
   		}
   %>
   
   <!-- goods_one begin-->
	<%   	
	if(id_1!=500)
	{	
   			for(i=0;i<shop_car.size();i++)
			{	
			if(goods.get(id_1).getName().equals(shop_car.get(i).getName())||goods.get(id_1).getPrice().equals(shop_car.get(i).getPrice()))
			{
						flag=1;
						break;
			}
			}	
				shop_car_bean=goods.get(id_1);	
				if(flag==0)
   			{
   				shop_car.add(shop_car_bean);
   			}
	}	
   			if(j<shop_car.size())
   			{
%>
   <div class="all_mid">
   <div class="all_mid_left">
   <div class="all_mid_left_name"><a>
   <%
   		out.print(shop_car.get(j).getName());
   	 %></a></div>
   </div>
   <div id="all_mid_mid">
   <div class="span_1">
   <span class="price"> 
   <%
   		out.print(shop_car.get(j).getPrice());
   	 %></span>
   </div>
   <div class="span_2"><a class="min">-</a><input class="text_box" type="text" value="1"></input><a class="add">+</a></div>
   
   </div>
   <div class="all_mid_right">
   <div class="all_min_right_a">
   <a href="http://localhost:8080/practise/jsp/delete_shop.jsp?j=<%=j %>" >删除</a> </div></div>
   </div>
   	<% 	 		
   			j++;
   			flag=0;
   		} 		
   		session.setAttribute("car_session", shop_car); 		
 	%>	
   <!-- goods_one  end -->

 <!-- goods_two begin-->
 			<%   	
	if(id_1!=500)
	{	
   			for(i=0;i<shop_car.size();i++)
			{
			if(goods.get(id_1).getName().equals(shop_car.get(i).getName())||goods.get(id_1).getPrice().equals(shop_car.get(i).getPrice()))
			{
						flag=1;
						break;
			}
			}	
				shop_car_bean=goods.get(id_1);	
				if(flag==0)
   			{
   			shop_car.add(shop_car_bean);
   			}
			}	
   			if(j<shop_car.size())
   			{
%>
   <div class="all_mid">
   <div class="all_mid_left">
   <div class="all_mid_left_name"><a>
   <%
   		out.print(shop_car.get(j).getName());
 		
   	 %></a></div>
   </div>
   <div id="all_mid_mid">
   <div class="span_1">
   <span class="price"> 
   <%
   		out.print(shop_car.get(j).getPrice());
   	 %></span>
   </div>
   <div class="span_2"><a class="min">-</a><input class="text_box" type="text" value="1"></input><a class="add">+</a></div>
   
   </div>
   <div class="all_mid_right">
   <div class="all_min_right_a">
   <a href="http://localhost:8080/practise/jsp/delete_shop.jsp?j=<%=j %>" >删除</a> </div></div>
   </div>
   	<% 	 		
   			j++;
   			flag=0;
   		} 		
   		session.setAttribute("car_session", shop_car); 		
 	%>	
  <!-- goods_two end -->
   
   
   
   <!-- goods_three begin -->
  	<%   	
	if(id_1!=500)
	{	
   			for(i=0;i<shop_car.size();i++)
			{
			if(goods.get(id_1).getName().equals(shop_car.get(i).getName())||goods.get(id_1).getPrice().equals(shop_car.get(i).getPrice()))
			{
						flag=1;
						break;
			}
			}	
				shop_car_bean=goods.get(id_1);	
				if(flag==0)
   			{
   			shop_car.add(shop_car_bean);
   			}
			}	
   			if(j<shop_car.size())
   			{
%>
   <div class="all_mid">
   <div class="all_mid_left">
   <div class="all_mid_left_name"><a>
   <%
   		out.print(shop_car.get(j).getName());
 		
   	 %></a></div>
   </div>
   <div id="all_mid_mid">
   <div class="span_1">
   <span class="price"> 
   <%
   		out.print(shop_car.get(j).getPrice());
   	 %></span>
   </div>
   <div class="span_2"><a class="min">-</a><input class="text_box" type="text" value="1"></input><a class="add">+</a></div>
   
   </div>
   <div class="all_mid_right">
   <div class="all_min_right_a">
  <a href="http://localhost:8080/practise/jsp/delete_shop.jsp?j=<%=j %>" >删除</a> </div></div>
   </div>
   	<% 	 		
   			j++;
   			flag=0;
   		} 		
   		session.setAttribute("car_session", shop_car); 		
 	%>	
   <!-- goods_three end -->
   
   
   
   
   
      <!-- goods_four begin -->
  	<%   	
	if(id_1!=500)
	{	
   			for(i=0;i<shop_car.size();i++)
			{
			if(goods.get(id_1).getName().equals(shop_car.get(i).getName())||goods.get(id_1).getPrice().equals(shop_car.get(i).getPrice()))
			{
						flag=1;
						break;
			}
			}	
				shop_car_bean=goods.get(id_1);	
				if(flag==0)
   			{
   			shop_car.add(shop_car_bean);
   			}
			}	
   			if(j<shop_car.size())
   			{
%>
   <div class="all_mid">
   <div class="all_mid_left">
   <div class="all_mid_left_name"><a>
   <%
   		out.print(shop_car.get(j).getName());
 		
   	 %></a></div>
   </div>
   <div id="all_mid_mid">
   <div class="span_1">
   <span class="price"> 
   <%
   		out.print(shop_car.get(j).getPrice());
   	 %></span>
   </div>
   <div class="span_2"><a class="min">-</a><input class="text_box" type="text" value="1"></input><a class="add">+</a></div>
   
   </div>
   <div class="all_mid_right">
   <div class="all_min_right_a">
   <a href="http://localhost:8080/practise/jsp/delete_shop.jsp?j=<%=j %>" >删除</a> </div></div>
   </div>
   	<% 	 		
   			j++;
   			flag=0;
   		} 		
   		session.setAttribute("car_session", shop_car); 		
 	%>	
   	<!-- goods_four end -->
   
   	  <!-- goods_five begin -->	
   	 	<%   	
	if(id_1!=500)
	{	
   			for(i=0;i<shop_car.size();i++)
			{
			if(goods.get(id_1).getName().equals(shop_car.get(i).getName())||goods.get(id_1).getPrice().equals(shop_car.get(i).getPrice()))
			{
						flag=1;
						break;
			}
			}	
				shop_car_bean=goods.get(id_1);	
				if(flag==0)
   			{
   			shop_car.add(shop_car_bean);
   			}
			}	
   			if(j<shop_car.size())
   			{
%>
   <div class="all_mid">
   <div class="all_mid_left">
   <div class="all_mid_left_name"><a>
   <%
   		out.print(shop_car.get(j).getName());
 		
   	 %></a></div>
   </div>
   <div id="all_mid_mid">
   <div class="span_1">
   <span class="price"> 
   <%
   		out.print(shop_car.get(j).getPrice());
   	 %></span>
   </div>
   <div class="span_2"><a class="min">-</a><input class="text_box" type="text" value="1"></input><a class="add">+</a></div>
   
   </div>
   <div class="all_mid_right">
   <div class="all_min_right_a">
  <a href="http://localhost:8080/practise/jsp/delete_shop.jsp?j=<%=j %>" >删除</a> </div></div>
   </div>
   	<% 	 		
   			j++;
   			flag=0;
   		} 		
   		session.setAttribute("car_session", shop_car); 		
 	%>	
   	<!-- goods_five end -->
   	

	  <div class="all_bottom">
   <div class="all_bottom_1"><div class="p1"><p>合计：</p></div><div class="p2"><p id="p2_2">¥</p></div></div>
   <div id="all_bottom_2" ><a href="http://localhost:8080/practise/jsp/inser_goods_my_sql.jsp">结算</a></div>
   </div>


   </div>
	<!-- all end -->
	
   
   

   
   
   
   
   
   <!-- body_content end -->
   
   <!-- bottom begin -->
   <div class="bottom_show">
   <div class="picture_1">
 	<a href="#"></a>
   </div>
   <div class="picture_2">
 <a href="#"></a>
   </div>   
   <div class="picture_3">
  <a href="#"></a>
   </div>
    <div class="picture_4">
  <a href="#"></a>
   </div>
   
   
   </div>
      <div class="bottom_bar"></div>
   <div class="bottom_word">
	<p>航空港校区 | 四川省成都市西南航空港经济开发区学府路一段24号 | 右边610225 | 电话:028-85966502</p>
	<p>龙泉校区 | 成都市龙泉驿阳光城幸福路10号 | 邮编:610103 | 电话:028-84833333</p>
	<p>Copyringht 2003_2014 成都信息工程大学 建议使用IE8.0,1034*860以上浏览</p>
   </div>
   <!-- bottom end -->
   
  </body>
</html>
